package controllers.api;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import models.Residence;
import play.mvc.Router;
import play.mvc.Http.StatusCode;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import controllers.BaseController;
import controllers.Data;
import exceptions.ValidationException;

public class Residences extends BaseController {
	
	public static void get() {
		Residence residence = Residence.findAll().get(0); 
		renderJSON(gson().toJson(residence));
	}
	
	public static void edit(Long id,  JsonObject body) {
		Residence residence = new Gson().fromJson(body, Residence.class);
		if(residence==null) {
			response.status = StatusCode.NOT_FOUND;
			return;
		}
		residence.update();
		response.status = StatusCode.OK;
		String url = Router.reverse("api.Residences.get").url;// GET /api/residence/
		response.setHeader("location", url);
	}
	
}